<layout name="../../../resource/master"/>
<section class="vbox">
    <section>
        <section class="hbox stretch">
            <!--.aside -->
            <section id="content">
                <section class="vbox">
                    <section class="scrollable padder">
                        <ul class="breadcrumb no-border no-radius b-b b-light pull-in">
                            <li><a href="{:u('add',['tid'=>$_GET['tid']])}"><i class="fa fa-home"></i> 首页</a></li>
                            <li><a href="">品牌管理</a></li>
                            <li class="active">添加品牌</li>
                        </ul>
                        <section class="panel panel-default">
                            <header class="panel-heading font-bold">
                                添加品牌
                            </header>
                            <div class="panel-body">
                                <form class="form-horizontal" id="form" method="post" action="">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"></label>
                                        <div class="col-sm-5"></div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">品牌名称</label>
                                        <div class="col-sm-5">
                                            <input type="text" name="bname" required class="form-control"
                                                   placeholder="分类名称长度 1 到 20 位">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="" class="col-sm-2 control-label">缩略图</label>
                                        <div class="col-sm-5">
                                            <div class="input-group">
                                                <input type="text" class="form-control" name="logo" readonly=""
                                                       value="">
                                                <div class="input-group-btn">
                                                    <button onclick="upImage(this)" class="btn btn-default"
                                                            type="button">选择图片
                                                    </button>
                                                </div>
                                            </div>
                                            <div class="input-group" style="margin-top:5px;">
                                                <img src="__ROOT__/node_modules/hdjs/images/nopic.jpg"
                                                     class="img-responsive img-thumbnail" width="150">
                                                <em class="close" style="position:absolute; top: 0px; right: -14px;"
                                                    title="删除这张图片" onclick="removeImg(this)">×</em>
                                            </div>

                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">品牌排序</label>
                                        <div class="col-sm-3">
                                            <input type="text" name="rank" required class="form-control"
                                                   placeholder="请输入1到999之间的数">
                                        </div>
                                    </div>




                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">是否显示</label>
                                        <div class="col-sm-10">
                                            <label>
                                                是： <input type="radio" value="1" name="ishot"
                                                          checked="checked">
                                            </label>
                                            <label>
                                                否: <input type="radio" value="0" name="ishot">
                                            </label>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-sm-4 col-sm-offset-2">
                                            <!--<input type="hidden" name='tid' value="{$_GET['tid']}"/>-->
                                            <button class="btn btn-primary" id="btn" type="submit">确定添加</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </section>
                    </section>
                </section>
            </section>
        </section>
    </section>
</section>
<script>
    //上传图片
    function upImage(obj) {
        require(['util'], function (util) {
            options = {
                multiple: false,//是否允许多图上传
                //data是向后台服务器提交的POST数据
                data:{name:'后盾人',year:2099},
            };
            util.image(function (images) {          //上传成功的图片，数组类型 
                $("[name='logo']").val(images[0]);
                $(".img-thumbnail").attr('src', '__ROOT__/'+images[0]);
            }, options)
        });
    }

    //移除图片
    function removeImg(obj) {
        $(obj).prev('img').attr('src', '__ROOT__/node_modules/hdjs/images/nopic.jpg');
        $(obj).parent().prev().find('input').val('');
    }
</script>

<script>
    function store(obj)
    {
        //序列化获取表单数据
        var data=$(obj).serialize();
        $.post("{{u('store')}}",data,function(res){
            //res:{valid:1,message:'响应信息'}
            if(res.valid){
                //成功
                //提示框在hdjs手册中搜索消息框
                util.message(res.message,"{{u('index')}}",'success');
            }else{
                //失败
                util.message(res.message,"back",'error');
            }
        },'json')
        //组织表单提交
        return false;
    }
</script>

